package com.example.foo.product.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.product.model.Item;
import com.example.foo.product.query.ItemQuery;

@org.apache.ibatis.annotations.Mapper
public interface ItemDao extends com.example.core.dao.BaseDao<Item, Long> {

	public default PageResult<Item> findItems(ItemQuery itemQuery, Pageable pageable) {
		QueryWrapper<Item> queryWrapper = createQueryWithBaseIf(itemQuery);
		//
		if (itemQuery.getType() != null) {
			queryWrapper.eq("type", itemQuery.getType());
		}
		if (itemQuery.getState() != null) {
			queryWrapper.eq("state", itemQuery.getState());
		}
		if (StringUtils.isNotEmpty(itemQuery.getName())) {
			queryWrapper.like("name", itemQuery.getName());
		}
		return findPages(queryWrapper, pageable);
	}

}
